package com.hamster.crm.web;

import com.hamster.crm.pojo.AffiliatesProgramConfig;
import com.hamster.crm.service.AffiliatesProgramConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【后台】项目加盟设置  Controller
 * @author Tarry
 * @create 2019/12/23 14:52
 */
@RestController
@RequestMapping("affiliatesProgramConfig")
public class AffiliatesProgramConfigController {
    @Autowired
    AffiliatesProgramConfigService affiliatesProgramConfigService;

    /**
     * 获取项目加盟设置列表
     * @param department  0 普通项目加盟 1服务部项目加盟
     * @return  List<AffiliatesProgramConfig>
     */
    @GetMapping("list")
    public ResponseEntity<List<AffiliatesProgramConfig>> list(@RequestParam String department){
        List<AffiliatesProgramConfig> list = affiliatesProgramConfigService.list(department);

        return ResponseEntity.ok(list);
    }

    /**
     * 新增一条项目加盟设置
     * @param affiliatesProgramConfig  前端传参数时，设置好department的值
     *                                 0 普通项目加盟 1服务部项目加盟
     * @return 状态码 200
     */
    @PostMapping("insert")
    public ResponseEntity<Void> insert(@RequestBody AffiliatesProgramConfig affiliatesProgramConfig){
        affiliatesProgramConfigService.insert(affiliatesProgramConfig);
        return ResponseEntity.ok().build();
    }

    /**
     * 根据id删除指定 项目加盟设置
     * @param ids id 集合
     * @return 状态码 200
     */
    @PostMapping("delete")
    public ResponseEntity<Void> delete(@RequestBody List<String> ids){
        affiliatesProgramConfigService.delete(ids);
        return ResponseEntity.ok().build();
    }


    /**
     * 根据id，获取项目加盟设置
     * @param id
     * @return  AffiliatesProgramConfig
     */
    @GetMapping("get")
    public ResponseEntity<AffiliatesProgramConfig> get(@RequestParam String id){
        AffiliatesProgramConfig affiliatesProgramConfig = affiliatesProgramConfigService.get(id);
        return ResponseEntity.ok(affiliatesProgramConfig);
    }


    /**
     * 修改项目加盟设置
     * @param affiliatesProgramConfig
     * @return 状态码 200
     */
    @PostMapping("update")
    public ResponseEntity<Void> update(@RequestBody AffiliatesProgramConfig affiliatesProgramConfig){
        affiliatesProgramConfigService.update(affiliatesProgramConfig);
        return ResponseEntity.ok().build();
    }

}
